package com.hefei.garden.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hefei.garden.dao.UserMapper;
import com.hefei.garden.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/user")
public class TestController {
    @Autowired
    private UserMapper userMapper;

    @RequestMapping(value = "/insert")
    @ResponseBody
    public void readWriteTest() {
        User user = new User();
        user.setUname("张三");
        userMapper.insert(user);

        User user2 = new User();
        user2.setUname("李四");
        userMapper.insert(user2);

    }

    @RequestMapping(value = "/list")
    @ResponseBody
    public void testTx() {
        LambdaQueryWrapper<User> userLambdaQueryWrapper = new LambdaQueryWrapper<>();
        userLambdaQueryWrapper.eq(User::getUname, "李四");

        List<User> users = userMapper.selectList(userLambdaQueryWrapper);
        System.out.println("users = " + users);
    }

}
